﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace SplendidCRM.Ext.Helpers
{
    public static  class PoyFormat
    {
        public static string ToStandardDatetime(this string datetime)
        {
            if (datetime==null)
            {
                return string.Empty;
            }

            DateTime result;
            //var res = datetime.Length<8?false: DateTime.TryParseExact(datetime.Substring(0,8), "yyyyMMdd", null,DateTimeStyles.None, out result);
            var dateFormatString = datetime.Length < 9 ? "yyyyMMdd" : "yyyyMMddHHmmss";
            var res = DateTime.TryParseExact(datetime, dateFormatString, null, DateTimeStyles.None, out result);
            return !res || result.Equals(DateTime.MinValue)?datetime:result.ToString("dd/MM/yyyy HH:mm:ss");
        }
    }
}

